home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / hdf / unix / hdf3_2r2.lha / HDF3.2r2 / src / dfsdf.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-30  |  49.7 KB  |  1,615 lines

  1. /***************************************************************************
  2. *
  3. *
  4. *                         NCSA HDF version 3.2r2
  5. *                            October 30, 1992
  6. *
  7. * NCSA HDF Version 3.2 source code and documentation are in the public
  8. * domain.  Specifically, we give to the public domain all rights for future
  9. * licensing of the source code, all resale rights, and all publishing rights.
  10. *
  11. * We ask, but do not require, that the following message be included in all
  12. * derived works:
  13. *
  14. * Portions developed at the National Center for Supercomputing Applications at
  15. * the University of Illinois at Urbana-Champaign, in collaboration with the
  16. * Information Technology Institute of Singapore.
  17. *
  18. * THE UNIVERSITY OF ILLINOIS GIVES NO WARRANTY, EXPRESSED OR IMPLIED, FOR THE
  19. * SOFTWARE AND/OR DOCUMENTATION PROVIDED, INCLUDING, WITHOUT LIMITATION,
  20. * WARRANTY OF MERCHANTABILITY AND WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE
  21. *
  22. ****************************************************************************
  23. */
  24.  
  25. #ifdef RCSID
  26. static char RcsId[] = "@(#)$Revision: 1.7 $";
  27. #endif
  28. /*
  29. $Header: /hdf/hdf/v3.2r2/src/RCS/dfsdf.c,v 1.7 1992/10/30 18:36:52 koziol beta koziol $
  30.  
  31. $Log: dfsdf.c,v $
  32.  * Revision 1.7  1992/10/30  18:36:52  koziol
  33.  * Fixed casts in a bunch of functions to make the SGI ANSI compiler happy
  34.  *
  35.  * Revision 1.6  1992/10/27  22:18:31  koziol
  36.  * changed fortran stub for DFSDpre32() to use new calling interface
  37.  *
  38.  * Revision 1.5  1992/10/12  18:11:51  koziol
  39.  * Updated for v3.2r2 release
  40.  *
  41.  * Revision 1.4  1992/09/15  19:40:05  koziol
  42.  * Folded Shiming's intn changes and the changes to fix non-square datasets
  43.  *
  44.  * Revision 1.3  1992/09/11  14:15:04  koziol
  45.  * Changed Fortran stubs' parameter passing to use a new typedef, intf,
  46.  * which should be typed to the size of an INTEGER*4 in whatever Fortran
  47.  * compiler the C functions need to be compatible with.  (This is mostly
  48.  * for the PC and possibly for the Mac)
  49.  *
  50.  * Revision 1.2  1992/08/31  16:14:52  chouck
  51.  * Added Fortran support for calibration tags
  52.  *
  53.  * Revision 1.1  1992/08/25  21:40:44  koziol
  54.  * Initial revision
  55.  *
  56. */
  57. /*-----------------------------------------------------------------------------
  58.  * File:    dfsdF.c
  59.  * Purpose: C stubs for Fortran SDS routines
  60.  * Invokes: dfsd.c dfkit.c
  61.  * Contents: 
  62.  *  dsgdast:       Call DFSDgetdatastrs to get attributes of data
  63.  *  dsigdis:       Call DFSDgetdimstrs to get attributes of a dimension
  64.  *  dsgdisc:       Call DFSDgetdimscale to get scale for a dimension
  65.  *  dsgrang:       Call DFSDgetmaxmin to get max and min data values
  66.  *  dssdims:       Call DFSDsetdims to set dimensions for subsequent SDGs
  67.  *  dssdisc:       Call DFSDsetdimscale to set scale for subsequent SDGs
  68.  *  dssrang:       Call DFSDsetmaxmin to set max/min values for subsequent SDGs
  69.  *  dsclear:       Call DFSDclear to erase values set for subsequent SDGs
  70.  *  dsslens:       Call DFSDsetlengths to set maximum lengths of string
  71.  *  dsgdiln:       Call DFSDgetdimlen to get lengths of strings for a dimension
  72.  *  dsgdaln:       Call DFSDgetdatalen to get lengths of data strings
  73.  *  dsfirst:       Call DFSDrestart to get SDGs again from beginning of file
  74.  *  dspslc:        Call DFSDIputslice to write slice to file
  75.  *  dseslc:        Call DFSDendslice to end slice writes, write SDG to file
  76.  *  dspre32:       Call DFSDpre32 to test if the SDS was  written
  77.  *                      using HDF library previous to HDF3.2
  78.  *  dssnt:         Call DFSDsetNT to set number type
  79.  *  dsgnt:         Call DFSDgetNT to get number type for reading
  80.  *  dsigdim:       Call DFSDgetdims to get dimensions of next SDG
  81.  *  dsigdat:       Call DFSDgetdata to get data values
  82.  *  dsipdat:       Call DFSDIputdata to write SDG to new file
  83.  *  dsiadat:       Call DFSDIputdata to append SDG to existing file
  84.  *  dsigslc:       Call DFSDIgetslice to get slice from file
  85.  *  dsisslc:       Call DFSDstartslice to set up to write slice
  86.  *  dslref:        Call DFSDlastref to get ref of last SDS accessed
  87.  *  dsinum:        Call DFSDnumber to get number of SDG in the file
  88.  *  dfsdgetdatastrs_:Call DFSDgetdatastrs to get attributes of data
  89.  *  dfsdgetdimscale_:Call DFSDgetdimscale to get scale for a dimension
  90.  *  dfsdgetrange_:  Call DFSDgetmaxmin to get max and min data values
  91.  *  dfsdsetdims_:   Call DFSDsetdims to set dimensions for subsequent SDGs
  92.  *  dfsdsetdimscale_:Call DFSDsetdimscale to set scale for subsequent SDGs
  93.  *  dfsdsetrange_:  Call DFSDsetmaxmin to set max/min values for subsequent SDGs
  94.  *  dfsdclear_:     Call DFSDclear to erase values set for subsequent SDGs
  95.  *  dfsdsetlengths_:Call DFSDsetlengths to set maximum lengths of string
  96.  *  dfsdgetdimlen_: Call DFSDgetdimlen to get lengths of strings for a dimension
  97.  *  dfsdgetdatalen_:Call DFSDgetdatalen to get lengths of data strings
  98.  *  dfsdrestart_:   Call DFSDrestart to get SDGs again from beginning of file
  99.  *  dfsdputslice_:  Call DFSDIputslice to write slice to file
  100.  *  dfsdendslice_:  Call DFSDendslice to end slice writes, write SDG to file
  101.  *  dfsdpre32:      Call DFSDpre32 to test if the SDS was  written
  102.  *                      using HDF library previous to HDF3.2
  103.  *  dfsdsetnt_:     Call DFSDsetNT to set number type
  104.  *  dfsdgetnt_:        Call DFSDgetNT to get number type
  105.  *  dfsdlastref_:   Call DFSDlastref to get ref of last SDS accessed
  106.  * Remarks: no C stubs needed for the put string routines, only Fortran stubs
  107.  *---------------------------------------------------------------------------*/
  108.  
  109. #include "dfsd.h"
  110.  
  111. /*-----------------------------------------------------------------------------
  112.  * Name:    dsgdisc
  113.  * Purpose: Call DFSDgetdimscale to get scale for a dimension
  114.  * Inputs:  dim: dimension to get attributes for
  115.  *          maxsize: size of scale array
  116.  *          scale: array to return scale in
  117.  * Returns: 0 on success, -1 on failure with DFerror set
  118.  * Users:   HDF Fortran programmers
  119.  * Invokes: DFSDgetdimscale
  120.  *---------------------------------------------------------------------------*/
  121.  
  122.     FRETVAL(intf)
  123. #ifdef PROTOTYPE
  124. ndsgdisc(intf *dim, intf *maxsize, void *scale)
  125. #else
  126. ndsgdisc(dim, maxsize, scale)
  127.     intf *dim;
  128.     intf *maxsize;
  129.     void *scale;
  130. #endif /* PROTOTYPE */
  131. {
  132.     intn rank, cdim;
  133.     intf ret;
  134.     intn isndg;
  135.  
  136.     ret = DFSDIisndg(&isndg);
  137.     if (isndg)     {
  138.         ret = DFSDIgetrrank(&rank);
  139.         if (rank < *dim)
  140.             return FAIL;
  141.         cdim = rank - *dim + 1;
  142.     }
  143.     else cdim = *dim;
  144.  
  145.     return(DFSDgetdimscale(cdim, *maxsize, scale));
  146. }
  147.  
  148.  
  149. /*-----------------------------------------------------------------------------
  150.  * Name:    dsgrang
  151.  * Purpose: Call DFSDgetrange to get maximum and minimum data values
  152.  * Inputs:  pmax: float to return maximum in
  153.  *          pmin: float to return minimum in
  154.  * Returns: 0 on success, -1 on failure with DFerror set
  155.  * Users:   HDF Fortran programmers
  156.  * Invokes: DFSDgetrange
  157.  *---------------------------------------------------------------------------*/
  158.  
  159.     FRETVAL(intf)
  160. #ifdef PROTOTYPE
  161. ndsgrang(void *pmax, void *pmin)
  162. #else
  163. ndsgrang(pmax, pmin)
  164.     void *pmax, *pmin;
  165. #endif /* PROTOTYPE */
  166. {
  167.     return(DFSDgetrange(pmax, pmin));
  168. }
  169.  
  170.  
  171. /*-----------------------------------------------------------------------------
  172.  * Name:    dssdims
  173.  * Purpose: Call DFSDsetdims to set dimensions for subsequent SDGs
  174.  * Inputs:  rank: no of dimensions of SDG
  175.  *          dimsizes: array containing dimensions of SDG
  176.  * Returns: 0 on success, -1 on failure with DFerror set
  177.  * Users:   HDF Fortran programmers
  178.  * Invokes: DFSDsetdims
  179.  *---------------------------------------------------------------------------*/
  180.  
  181.     FRETVAL(intf)
  182. #ifdef PROTOTYPE
  183. ndssdims(intf *rank, intf dimsizes[])
  184. #else
  185. ndssdims(rank, dimsizes)
  186.     intf *rank;
  187.     intf dimsizes[];
  188. #endif /* PROTOTYPE */
  189. {
  190.     int32 i, *cdims, *p;
  191.     intf ret;
  192.  
  193.     p = (int32 *)HDgetspace((uint32)((*rank)*sizeof(int32)));
  194.     if (p == NULL) return FAIL;
  195.     cdims = p;
  196.     for (i=1; i <=  *rank ; i++)    {
  197.         *p = dimsizes[*rank - i];
  198.         p++;
  199.     }
  200.    
  201.     ret = DFSDsetdims((intn)*rank, cdims);
  202.     cdims = HDfreespace((uint32 *)cdims);
  203.     if (cdims != NULL) return FAIL;
  204.     return(ret);
  205. }
  206.  
  207.  
  208. /*-----------------------------------------------------------------------------
  209.  * Name:    dssdisc
  210.  * Purpose: Call DFSDsetdimscale to set scales for subsequent SDGs
  211.  * Inputs:  dim: dimension to set scale for
  212.  *          dimsize: size of array scale
  213.  *          scale: array of scale values
  214.  * Returns: 0 on success, -1 on failure with DFerror set
  215.  * Users:   HDF Fortran programmers
  216.  * Invokes: DFSDsetdimscale
  217.  *---------------------------------------------------------------------------*/
  218.  
  219.     FRETVAL(intf)
  220. #ifdef PROTOTYPE
  221. ndssdisc(intf *dim, intf *dimsize, void *scale)
  222. #else
  223. ndssdisc(dim, dimsize, scale)
  224.     intf *dim;
  225.     intf *dimsize;
  226.     void *scale;
  227. #endif /* PROTOTYPE */
  228. {
  229.     int cdim, ret;
  230.     intn rank;
  231.  
  232.     ret = DFSDIgetwrank(&rank);
  233.     if (rank < *dim) return FAIL;
  234.     cdim = rank - *dim + 1;
  235.  
  236.     return(DFSDsetdimscale(cdim, *dimsize, scale));
  237. }
  238.  
  239.  
  240. /*-----------------------------------------------------------------------------
  241.  * Name:    dssrang
  242.  * Purpose: Call DFSDsetrange to set max and min values for this SDG
  243.  * Inputs:  max, min: max and min data values
  244.  * Returns: 0 on success, -1 on failure with DFerror set
  245.  * Users:   HDF Fortran programmers
  246.  * Invokes: DFSDsetrange
  247.  * Remarks: Max and Min are set only for next SDG, reset to NULL after
  248.  *---------------------------------------------------------------------------*/
  249.  
  250.     FRETVAL(intf)
  251. #ifdef PROTOTYPE
  252. ndssrang(void *max, void *min)
  253. #else
  254. ndssrang(max, min)
  255.     void *max, *min;
  256. #endif /* PROTOTYPE */
  257. {
  258.     return(DFSDsetrange(max, min));
  259. }
  260.  
  261.  
  262. /*-----------------------------------------------------------------------------
  263.  * Name:    dsclear
  264.  * Purpose: Call DFSDclear to erase values set for subsequent SDGs
  265.  * Inputs:  none
  266.  * Returns: 0 on success, -1 on failure with DFerror set
  267.  * Users:   HDF Fortran programmers
  268.  * Invokes: DFSDclear
  269.  *---------------------------------------------------------------------------*/
  270.  
  271.     FRETVAL(intf)
  272. #ifdef PROTOTYPE
  273. ndsclear(void)
  274. #else
  275. ndsclear()
  276. #endif /* PROTOTYPE */
  277. {
  278.     return(DFSDclear());
  279. }
  280.  
  281.  
  282. /*-----------------------------------------------------------------------------
  283.  * Name:    dsslens
  284.  * Purpose: Call DFSDsetlengths to set max lengths of strings
  285.  * Inputs:  maxlen_label, maxlen_unit, maxlen_format, maxlen_coordsys: max lens
  286.  * Returns: 0 on success, -1 on failure with DFerror set
  287.  * Users:   HDF Fortran programmers
  288.  * Invokes: DFSDsetlengths
  289.  *---------------------------------------------------------------------------*/
  290.  
  291.     FRETVAL(intf)
  292. #ifdef PROTOTYPE
  293. ndsslens(intf *maxlen_label, intf *maxlen_unit, intf *maxlen_format,
  294.      intf *maxlen_coordsys)
  295. #else
  296. ndsslens(maxlen_label, maxlen_unit, maxlen_format, maxlen_coordsys)
  297.     intf *maxlen_label,
  298.         *maxlen_unit,
  299.         *maxlen_format,
  300.         *maxlen_coordsys;
  301. #endif /* PROTOTYPE */
  302. {
  303.     return(DFSDsetlengths(*maxlen_label, *maxlen_unit, *maxlen_format,
  304.                                     *maxlen_coordsys));
  305. }
  306.  
  307.  
  308. /*-----------------------------------------------------------------------------
  309.  * Name:    dsgdiln
  310.  * Purpose: Call DFSDgetdimlen to get actual lengths of strings
  311.  * Inputs:  dim: dimension to get lengths for
  312.  *          llabel, lunit, lformat: integers to return lengths of each string in
  313.  * Returns: 0 on success, -1 on failure with DFerror set
  314.  * Users:   HDF Fortran programmers
  315.  * Invokes: DFSDgetdimlen
  316.  *---------------------------------------------------------------------------*/
  317.  
  318.     FRETVAL(intf)
  319. #ifdef PROTOTYPE
  320. ndsgdiln(intf *dim, intf *llabel, intf *lunit, intf *lformat)
  321. #else
  322. ndsgdiln(dim, llabel, lunit, lformat)
  323.     intf *dim, *llabel, *lunit, *lformat;
  324. #endif /* PROTOTYPE */
  325. {
  326.     intn rank, cdim;
  327.     intf ret;
  328.     intn isndg;
  329.  
  330.     ret = DFSDIisndg(&isndg);
  331.     if (isndg)     {
  332.         ret = DFSDIgetrrank(&rank);
  333.         if (rank < *dim)
  334.             return FAIL;
  335.         cdim = rank - *dim + 1;
  336.     }
  337.     else cdim = *dim;
  338.  
  339.     return(DFSDgetdimlen(cdim, llabel, lunit, lformat));
  340. }
  341.  
  342.  
  343. /*-----------------------------------------------------------------------------
  344.  * Name:    dsgdaln
  345.  * Purpose: Call DFSDgetdatalen to get actual lengths of strings
  346.  * Inputs:  llabel, lunit, lformat, lcoordsys: integers to return lengths in
  347.  * Returns: 0 on success, -1 on failure with DFerror set
  348.  * Users:   HDF Fortran programmers
  349.  * Invokes: DFSDgetdatalen
  350.  *---------------------------------------------------------------------------*/
  351.  
  352.     FRETVAL(intf)
  353. #ifdef PROTOTYPE
  354. ndsgdaln(intf *llabel, intf *lunit, intf *lformat, intf *lcoordsys)
  355. #else
  356. ndsgdaln(llabel, lunit, lformat, lcoordsys)
  357.     intf *llabel, *lunit, *lformat, *lcoordsys;
  358. #endif /* PROTOTYPE */
  359. {
  360.  
  361.     return(DFSDgetdatalen(llabel, lunit, lformat, lcoordsys));
  362. }
  363.  
  364.  
  365. /*----------------------------------------------------------------------------- 
  366.  * Name:    dsfirst * Purpose: Call DFSDrestart to get SDGs again from the beginning
  367.  * Inputs:  none
  368.  * Returns: 0 on success, -1 on failure with DFerror set
  369.  * Users:   HDF Fortran programmers
  370.  * Invokes: DFSDrestart
  371.  *---------------------------------------------------------------------------*/
  372.  
  373.     FRETVAL(intf)
  374. #ifdef PROTOTYPE
  375. ndsfirst(void)
  376. #else
  377. ndsfirst()
  378. #endif /* PROTOTYPE */
  379. {
  380.  
  381.     return(DFSDrestart());
  382. }
  383.  
  384.  
  385. /*-----------------------------------------------------------------------------
  386.  * Name:    dspslc
  387.  * Purpose: Call DFSDIputslice to write slice to file 
  388.  * Inputs:  windims: array of size rank, containing size of slice 
  389.  *          data: array containing slice 
  390.  *          dims: dimensions of array data 
  391.  * Returns: 0 on success, -1 on failure with DFerror set
  392.  * Users:   HDF Fortran programmers
  393.  * Invokes: DFSDIputslice
  394.  *---------------------------------------------------------------------------*/
  395.  
  396.     FRETVAL(intf)
  397. #ifdef PROTOTYPE
  398. ndspslc(intf windims[], void *data, intf dims[])
  399. #else
  400. ndspslc(windims, data, dims)
  401.     intf windims[];
  402.     void  *data;
  403.     intf dims[];
  404. #endif /* PROTOTYPE */
  405. {
  406.     int32 *cdims, *cwindims, *p, *wp;
  407.     intn i, rank;
  408.     intf ret;
  409.  
  410.     ret = DFSDIgetwrank(&rank);
  411.     wp = (int32 *)HDgetspace((uint32)(rank*sizeof(int32)));
  412.     if (wp == NULL) return FAIL;
  413.     cwindims = wp;
  414.     p = (int32 *)HDgetspace((uint32)(rank*sizeof(int32)));
  415.     if (p == NULL) return FAIL;
  416.     cdims = p;
  417.     for (i=1; i <=  rank ; i++)    {  /* reverse dims & windims */
  418.         *p = dims[rank - i];
  419.         p++;
  420.         *wp = windims[rank - i];
  421.         wp++;
  422.     }
  423.    
  424.     ret = DFSDIputslice(cwindims, data, cdims, 1);
  425.     cdims = HDfreespace((uint32 *)cdims);
  426.     if (cdims != NULL) return FAIL;
  427.     cwindims = HDfreespace((uint32 *)cwindims);
  428.     if (cwindims != NULL) return FAIL;
  429.     return(ret);
  430. }
  431.  
  432.  
  433. /*-----------------------------------------------------------------------------
  434.  * Name:    dseslc
  435.  * Purpose: Call DFSDIendslice to finish slice writes and write out SDG
  436.  * Inputs:  none
  437.  * Returns: 0 on success, -1 on failure with DFerror set
  438.  * Users:   HDF Fortran programmers
  439.  * Invokes: DFSDIendslice
  440.  *---------------------------------------------------------------------------*/
  441.  
  442.     FRETVAL(intf)
  443. #ifdef PROTOTYPE
  444. ndseslc(void)
  445. #else
  446. ndseslc()
  447. #endif /* PROTOTYPE */
  448. {
  449.  
  450.     return(DFSDIendslice(1));
  451. }
  452.  
  453.  
  454. /*-----------------------------------------------------------------------------
  455.  * Name:    dspre32
  456.  * Purpose: test if the SDS was  written using HDF library previous 
  457.  *          to HDF3.2
  458.  * Returns: TRUE if written by 3.1, FALSE if by 3.2
  459.  * Users:   HDF Fortran programmers
  460.  * Method:  Invokes DFSDpre32
  461.  * Remarks: 0 specifies default value
  462.  *---------------------------------------------------------------------------*/
  463.  
  464.         FRETVAL(intf)
  465. #ifdef PROTOTYPE
  466. ndspre32(void)
  467. #else
  468. ndspre32()
  469. #endif /* PROTOTYPE */
  470. {
  471.     return(DFSDpre32());
  472. }
  473.  
  474. /*-----------------------------------------------------------------------------
  475.  * Name:    dssnt
  476.  * Purpose: Call DFSDsetNT to set number type for subsequent calls to
  477.             DFSDputdata, DFSDadddata, DFSDsetdimscales.
  478.  * Inputs:  numbertype
  479.  * Returns: 0 on success, FAIL on failure with error set
  480.  * Users:   HDF Fortran programmers
  481.  * Method:  Invokes DFSDsetNT
  482.  * Remarks: 0 specifies default value
  483.  *---------------------------------------------------------------------------*/
  484.  
  485.         FRETVAL(intf)
  486. #ifdef PROTOTYPE
  487. ndssnt(intf *numbertype)
  488. #else
  489. ndssnt(numbertype)
  490.     intf *numbertype;
  491. #endif /* PROTOTYPE */
  492. {
  493.     return(DFSDsetNT(*numbertype));
  494. }
  495.  
  496. /*----------------------------------------------------------------------------
  497.  * Name:    dsgnt
  498.  * Purpose: Call DFSDgetNT to get number type for subsequent calls 
  499.  * Inputs:  pnumbertype
  500.  * Returns: 0 on success, FAIL on failure with error set
  501.  * Users:   HDF Fortran programmers
  502.  * Method:  Invokes DFSDgetNT
  503.  * Remarks: 0 specifies default value
  504.  *---------------------------------------------------------------------------*/
  505.  
  506.         FRETVAL(intf)
  507. #ifdef PROTOTYPE
  508. ndsgnt(intf *pnumbertype)
  509. #else
  510. ndsgnt(pnumbertype)
  511.     intf *pnumbertype;
  512. #endif /* PROTOTYPE */
  513. {
  514.     return(DFSDgetNT((int32 *)pnumbertype));
  515. }
  516.  
  517.  
  518. /*-----------------------------------------------------------------------------
  519.  * Name:    dsigdim
  520.  * Purpose: Call DFSDgetdims to get dimensions of next SDG
  521.  * Inputs:  filename: name of HDF file
  522.  *          prank: integer to return rank in
  523.  *          sizes: array to return dimensions in
  524.  *          maxrank: dimension of array sizes
  525.  *          lenfn: length of filename
  526.  * Returns: 0 on success, -1 on failure with DFerror set
  527.  * Users:   Fortran stub routine
  528.  * Invokes: DFSDgetdims
  529.  *---------------------------------------------------------------------------*/
  530.  
  531.     FRETVAL(intf)
  532. #ifdef PROTOTYPE
  533. ndsigdim(_fcd filename, intf *prank, intf sizes[], intf *maxrank,
  534.      intf *lenfn)
  535. #else
  536. ndsigdim(filename, prank, sizes, maxrank, lenfn)
  537.     _fcd filename;
  538.     intf *prank, sizes[], *maxrank, *lenfn;
  539. #endif /* PROTOTYPE */
  540. {
  541.     char *fn;
  542.     int32 i, tmp;
  543.     intn  isndg;
  544.     intf ret;
  545.  
  546.     fn = HDf2cstring(filename, (intn)*lenfn);
  547.     ret = DFSDgetdims(fn,(intn *) prank, (int32 *)sizes, (intn) *maxrank);
  548.     DFSDIisndg(&isndg);
  549.     if (isndg) {
  550.         for (i=0; i<((int32)*prank)/2; i++) {
  551.             tmp = sizes[i];
  552.             sizes[i] = sizes[(int32)*prank -i -1];
  553.             sizes[(int32)*prank -i -1] = tmp;
  554.         }
  555.     }
  556.     HDfreespace(fn);
  557.     return ret;
  558. }
  559.  
  560.  
  561. /*-----------------------------------------------------------------------------
  562.  * Name:    dsigdat
  563.  * Purpose: Call DFSDgetdata to get data values
  564.  * Inputs:  filename: name of HDF file
  565.  *          rank: no of dimensions in array data
  566.  *          maxsizes: array containing dimensions of the array data
  567.  *          data: array to return the data in
  568.  * Returns: 0 on success, -1 on failure with DFerror set
  569.  * Users:   HDF Fortran programmers
  570.  * Invokes: DFSDIgetdata,DFSDIrefresh,DFSDIisndg
  571.  *---------------------------------------------------------------------------*/
  572.  
  573.     FRETVAL(intf)
  574. #ifdef PROTOTYPE
  575. ndsigdat(_fcd filename, intf *rank, intf maxsizes[], void *data, intf *fnlen)
  576. #else
  577. ndsigdat(filename, rank, maxsizes, data, fnlen)
  578.     _fcd filename;
  579.     intf *rank, maxsizes[], *fnlen;
  580.     void *data;
  581. #endif /* PROTOTYPE */
  582. {
  583.     int32 i;
  584.     intn  isndg;
  585.     intf ret;
  586.     char *fn;
  587.     int32 *p, *cmaxsizes;
  588.     
  589.     fn = HDf2cstring(filename, (intn) *fnlen);
  590.       /* if DFSDgetdims has not be called call DFSDIsdginfo to */
  591.       /* refresh Readsdg       */
  592.     if (DFSDIrefresh(fn)<0) return FAIL;
  593.     ret = DFSDIisndg(&isndg);
  594.     if (isndg)    {
  595.         p = (int32 *)HDgetspace((uint32)((*rank)*sizeof(int32)));
  596.         if (p == NULL) return FAIL;
  597.         cmaxsizes = p;
  598.  
  599.         for (i=1; i <=  *rank ; i++)    {
  600.             *p = maxsizes[*rank - i];
  601.             p++;
  602.         }
  603.         ret = DFSDIgetdata(fn, (intn)*rank, cmaxsizes, data, 1);
  604.         p = cmaxsizes = HDfreespace((uint32 *)cmaxsizes);
  605.         if (cmaxsizes != NULL) return FAIL;
  606.     }
  607.     else    
  608.         ret = DFSDIgetdata(fn, (intn)*rank, (int32 *)maxsizes, data, 1); /* 1==FORTRAN */
  609.     HDfreespace(fn);
  610.     return ret;
  611. }
  612.  
  613.  
  614. /*-----------------------------------------------------------------------------
  615.  * Name:    dsipdat
  616.  * Purpose: Call DFSDIputdata to write SDG to new file
  617.  * Inputs:  filename: name of HDF file
  618.  *          rank: no of dimensions of array data
  619.  *          dimsizes: array containing size of each dimension of array data
  620.  *          data: array containing data values
  621.  *          fnlen: length of string filename
  622.  * Returns: 0 on success, -1 on failure with DFerror set
  623.  * Users:   HDF Fortran programmers
  624.  * Invokes: DFSDIputdata
  625.  *---------------------------------------------------------------------------*/
  626.  
  627.     FRETVAL(intf)
  628. #ifdef PROTOTYPE
  629. ndsipdat(_fcd filename, intf *rank, intf dimsizes[], void *data, intf *fnlen)
  630. #else
  631. ndsipdat(filename, rank, dimsizes, data, fnlen)
  632.     _fcd filename;
  633.     intf *rank;
  634.     intf dimsizes[];
  635.     void *data;
  636.     intf *fnlen;
  637. #endif /* PROTOTYPE */
  638. {
  639.     char *fn;
  640.     int32 i, *cdims, *p;
  641.     intf ret;
  642.  
  643.     /* reverse the dimsizes first  */
  644.     p = (int32 *)HDgetspace((uint32)((*rank)*sizeof(int32)));
  645.     if (p == NULL) return FAIL;
  646.     cdims = p;
  647.     for (i=1; i <=  *rank ; i++)    {
  648.         *p = dimsizes[*rank - i];
  649.         p++;
  650.     }
  651.     fn = HDf2cstring(filename, (intn) *fnlen);
  652.  
  653.     /* 0, 1 specify create mode, called from FORTRAN program */
  654.     /* In HDF3.2 .hdf files, data and dimsizes are in C order  */
  655.     ret = DFSDIputdata(fn, (intn)*rank, cdims, data, 0, 1);
  656.     HDfreespace(fn);
  657.     cdims = HDfreespace((uint32 *)cdims);
  658.     if (cdims != NULL) return FAIL;
  659.  
  660.     return(ret);
  661. }
  662.  
  663.  
  664. /*-----------------------------------------------------------------------------
  665.  * Name:    dsiadat
  666.  * Purpose: Call DFSDIputdata to append SDG to existing file
  667.  * Inputs:  filename: name of HDF file
  668.  *          rank: no of dimensions of array data
  669.  *          dimsizes: array containing size of each dimension of array data
  670.  *          data: array containing data values
  671.  *          fnlen: length of string filename
  672.  * Returns: 0 on success, -1 on failure with DFerror set
  673.  * Users:   HDF Fortran programmers
  674.  * Invokes: DFSDIputdata
  675.  *---------------------------------------------------------------------------*/
  676.  
  677.     FRETVAL(intf)
  678. #ifdef PROTOTYPE
  679. ndsiadat(_fcd filename, intf *rank, intf dimsizes[], void *data, intf *fnlen)
  680. #else
  681. ndsiadat(filename, rank, dimsizes, data, fnlen)
  682.     _fcd filename;
  683.     intf *rank;
  684.     intf dimsizes[];
  685.     void *data;
  686.     intf *fnlen;
  687. #endif /* PROTOTYPE */     
  688. {
  689.     char *fn;
  690.     int32 i,  *cdims, *p;
  691.     intf ret;
  692.  
  693.     /* reverse the dimsizes first  */
  694.     p = (int32 *)HDgetspace((uint32)((*rank)*sizeof(int32)));
  695.     if (p == NULL) return FAIL;
  696.     cdims = p;
  697.     for (i=1; i <=  *rank ; i++) {
  698.         *p = dimsizes[*rank - i];
  699.         p++;
  700.     }
  701.     fn = HDf2cstring(filename, (intn) *fnlen);
  702.    
  703.     /* 1, 1 specify create mode, called from FORTRAN program */
  704.     /* In HDF3.2 .hdf files, data and dimsizes are in C order  */
  705.     ret = DFSDIputdata(fn, (intn)*rank, cdims, data, 1, 1);
  706.     HDfreespace(fn);
  707.     cdims = HDfreespace((uint32 *)cdims);
  708.     if (cdims != NULL) return FAIL;
  709.     return(ret);
  710. }
  711.  
  712.  
  713. /*-----------------------------------------------------------------------------
  714.  * Name:    dsigslc
  715.  * Purpose: Call DFSDIgetslice to read slice from file
  716.  * Inputs:  filename: name of HDF file
  717.  *          winst: array of size = rank of data, containing start of slice
  718.  *          windims: array of size rank, containing end of slice
  719.  *          data: array for returning slice
  720.  *          ndims: no of dims of array data
  721.  *          dims: dimensions of array data
  722.  *          fnlen: length of filename
  723.  * Returns: 0 on success, -1 on failure with DFerror set
  724.  * Users:   HDF Fortran programmers
  725.  * Invokes: DFSDIgetslice
  726.  *---------------------------------------------------------------------------*/
  727.  
  728.     FRETVAL(intf)
  729. #ifdef PROTOTYPE
  730. ndsigslc(_fcd filename, intf winst[], intf windims[], void *data, intf dims[],
  731.     intf *fnlen)
  732. #else
  733. ndsigslc(filename, winst, windims, data, dims, fnlen)
  734.     _fcd filename;
  735.     intf winst[], windims[];
  736.     intf dims[];
  737.     void *data;
  738.     intf *fnlen;
  739. #endif /* PROTOTYPE */
  740. {
  741.     char *fn;
  742.     intf ret;
  743.     intn rank,i;
  744.     int32 *cdims, *cwindims, *cwinst, *p, *wp, *wsp;
  745.     intn isndg;
  746.  
  747.     fn = HDf2cstring(filename, *fnlen);
  748.    
  749.       /* if DFSDgetdims has not be called call DFSDIsdginfo to */
  750.       /* refresh Readsdg       */
  751.     if (DFSDIrefresh(fn)<0) return FAIL;
  752.  
  753.     ret = DFSDIisndg(&isndg);
  754.     if (isndg)    {
  755.     ret = DFSDIgetrrank(&rank);
  756.         p = (int32 *)HDgetspace((uint32)(rank*sizeof(int32)));
  757.         if (p == NULL) return FAIL;
  758.         cdims = p;
  759.         wp = (int32 *)HDgetspace((uint32)(rank*sizeof(int32)));
  760.         if (wp == NULL) return FAIL;
  761.         cwindims = wp;
  762.         wsp = (int32 *)HDgetspace((uint32)(rank*sizeof(int32)));
  763.         if (wsp == NULL) return FAIL;
  764.         cwinst = wsp;
  765.  
  766.         for (i=1; i <=  rank ; i++)    {
  767.             *p = dims[rank - i];
  768.             p++;
  769.             *wp = windims[rank - i];
  770.             wp++;
  771.             *wsp = winst[rank - i];
  772.             wsp++;
  773.         }
  774.         ret = DFSDIgetslice(fn, cwinst, cwindims, data, cdims, 1);
  775.         p = cdims = HDfreespace((uint32 *)cdims);
  776.         if (cdims != NULL) return FAIL;
  777.         wp = cwindims = HDfreespace((uint32 *)cwindims);
  778.         if (cwindims != NULL) return FAIL;
  779.         wsp = cwinst = HDfreespace((uint32 *)cwinst);
  780.         if (cwinst != NULL) return FAIL;
  781.     }
  782.     else    
  783.         ret = DFSDIgetslice(fn, (int32 *)winst, (int32 *)windims, 
  784.                 data, (int32 *)dims, 1);
  785.     HDfreespace(fn);
  786.     return(ret);
  787. }
  788.  
  789.  
  790. /*-----------------------------------------------------------------------------
  791.  * Name:    dsisslc
  792.  * Purpose: Call DFSDstartslice to set up to write slice
  793.  * Inputs:  filename: name of HDF file
  794.  *          fnlen: length of filename
  795.  * Returns: 0 on success, -1 on failure with DFerror set
  796.  * Users:   HDF Fortran programmers
  797.  * Invokes: DFSDstartslice
  798.  *---------------------------------------------------------------------------*/
  799.  
  800.     FRETVAL(intf)
  801. #ifdef PROTOTYPE
  802. ndsisslc(_fcd filename, intf *fnlen)
  803. #else
  804. ndsisslc(filename, fnlen)
  805.     _fcd filename;
  806.     intf *fnlen;
  807. #endif /* PROTOTYPE */
  808. {
  809.     char *fn;
  810.     intf ret;
  811.  
  812.     fn = HDf2cstring(filename, *fnlen);
  813.     ret = DFSDstartslice(fn);
  814.     HDfreespace(fn);
  815.     return(ret);
  816. }
  817.  
  818. /*-----------------------------------------------------------------------------
  819.  * Name:    dsirref
  820.  * Purpose: Call DFSDreadref to set up next ref to read
  821.  * Inputs:  filename: name of HDF file
  822.  *        ref: next ref to read
  823.  *          fnlen: length of filename
  824.  * Returns: 0 on success, -1 on failure with DFerror set
  825.  * Users:   HDF Fortran programmers
  826.  * Invokes: DFSDstartslice
  827.  *---------------------------------------------------------------------------*/
  828.  
  829.     FRETVAL(intf)
  830. #ifdef PROTOTYPE
  831. ndsirref(_fcd filename, intf *ref, intf *fnlen)
  832. #else
  833. ndsirref(filename, ref, fnlen)
  834.     _fcd filename;
  835.     intf *ref;
  836.     intf *fnlen;
  837. #endif /* PROTOTYPE */
  838. {
  839.     char *fn;
  840.     intf ret;
  841.  
  842.     fn = HDf2cstring(filename, *fnlen);
  843.     ret = DFSDreadref(fn, (uint16) *ref);
  844.     HDfreespace(fn);
  845.     return(ret);
  846. }
  847.  
  848. /*-----------------------------------------------------------------------------
  849.  * Name:    dslref
  850.  * Purpose: Return last ref written or read
  851.  * Inputs:  none
  852.  * Globals: Lastref
  853.  * Returns: ref on success, -1 on error with DFerror set
  854.  * Users:   HDF users, utilities, other routines
  855.  * Invokes: DFANlastref
  856.  * Remarks: none
  857.  *---------------------------------------------------------------------------*/
  858.  
  859.     FRETVAL(intf)
  860. #ifdef PROTOTYPE  
  861. ndslref(void)
  862. #else
  863. ndslref()
  864. #endif /* PROTOTYPE */
  865. {
  866.     return(DFSDlastref());
  867. }
  868.  
  869.  
  870. /*-----------------------------------------------------------------------------
  871.  * Name:    dsinum
  872.  * Purpose: Return number of SDGs in the file
  873.  * Inputs:  filename: name of file
  874.  *          len: length of Fortran string filename
  875.  * Returns: number of SDGs on success, -1 on failure with DFerror set
  876.  * Users:   dsnum, dfsdnumber
  877.  * Invokes: DFSDnumber, HDf2cstring
  878.  * Method:  convert string, call DFSDnumber
  879.  *---------------------------------------------------------------------------*/
  880.  
  881.     FRETVAL(intf)
  882. #ifdef PROTOTYPE  
  883. ndsinum(_fcd filename, intf *len)
  884. #else
  885. ndsinum(filename, len)
  886.     _fcd filename;
  887.     intf *len;
  888. #endif /* PROTOTYPE */
  889. {
  890.     char *cname;
  891.     intf status;
  892.  
  893.     cname = HDf2cstring(filename, (intn) *len);
  894.     status = DFSDnumber(cname);
  895.     HDfreespace(cname);
  896.  
  897.     return(status);
  898. }
  899.  
  900.  
  901. /*-----------------------------------------------------------------------------
  902.  * Name:    dfsdgetdatastrs
  903.  * Purpose: Call DFSDgetdatastrs to get the data attributes
  904.  * Inputs:  label, unit, format, coordsys: strings to return attributes in
  905.  * Returns: 0 on success, -1 on failure with DFerror set
  906.  * Users:   HDF Fortran programmers
  907.  * Invokes: DFSDgetdatastrs
  908.  *---------------------------------------------------------------------------*/
  909.  
  910.     FRETVAL(intf)
  911. #ifdef PROTOTYPE
  912. ndfsdgetdatastrs(_fcd label, _fcd unit, _fcd format, _fcd coordsys)
  913. #else
  914. ndfsdgetdatastrs(label, unit, format, coordsys)
  915.     _fcd label, unit, format, coordsys;
  916. #endif /* PROTOTYPE */
  917. {
  918.     return(DFSDgetdatastrs((char *)_fcdtocp(label), (char *)_fcdtocp(unit),
  919.              (char *)_fcdtocp(format), (char *)_fcdtocp(coordsys)));
  920. }
  921.  
  922.  
  923. /*-----------------------------------------------------------------------------
  924.  * Name:    dfsdgetdimstrs
  925.  * Purpose: Call DFSDgetdimstrs to get attributes of a dimension
  926.  * Inputs:  label, unit, format: strings to return attributes in
  927.  * Returns: 0 on success, -1 on failure with DFerror set
  928.  * Users:   HDF Fortran programmers
  929.  * Invokes: DFSDgetdimstrs
  930.  *---------------------------------------------------------------------------*/
  931.  
  932.     FRETVAL(intf)
  933. #ifdef PROTOTYPE
  934. ndfsdgetdimstrs(intf *dim, _fcd label, _fcd unit, _fcd format)
  935. #else
  936. ndfsdgetdimstrs(dim, label, unit, format)
  937.     intf *dim;
  938.     _fcd label, unit, format;
  939. #endif /* PROTOTYPE */
  940. {
  941.     intn isndg;
  942.     intn rank, cdim;
  943.     intf ret;
  944.  
  945.     ret = DFSDIisndg(&isndg);
  946.     if (isndg)     {
  947.         ret = DFSDIgetrrank(&rank);
  948.         if (rank < *dim) return FAIL;
  949.         cdim = rank - *dim + 1;
  950.     }
  951.     else cdim = *dim;
  952.  
  953.     return(DFSDgetdimstrs(cdim, (char *)_fcdtocp(label),
  954.               (char *)_fcdtocp(unit), (char *)_fcdtocp(format)));
  955. }
  956.  
  957.  
  958. /*-----------------------------------------------------------------------------
  959.  * Name:    dfsdgetdimscale
  960.  * Purpose: Call DFSDgetdimscale to get scale for a dimension
  961.  * Inputs:  dim: dimension to get attributes for
  962.  *          maxsize: size of scale array
  963.  *          scale: array to return scale in
  964.  * Returns: 0 on success, -1 on failure with DFerror set
  965.  * Users:   HDF Fortran programmers
  966.  * Invokes: DFSDgetdimscale
  967.  *---------------------------------------------------------------------------*/
  968.  
  969.     FRETVAL(intf)
  970. #ifdef PROTOTYPE
  971. ndfsdgetdimscale(intf *dim, intf *maxsize, void *scale)
  972. #else
  973. ndfsdgetdimscale(dim, maxsize, scale)
  974.     intf *dim;
  975.     intf *maxsize;
  976.     void *scale;
  977. #endif /* PROTOTYPE */
  978. {
  979.  
  980.     intn isndg;
  981.     intn  rank, cdim, ret;
  982.  
  983.     ret = DFSDIisndg(&isndg);
  984.     if (isndg)     {
  985.         ret = DFSDIgetrrank(&rank);
  986.         if (rank < *dim) return FAIL;
  987.         cdim = rank - *dim + 1;
  988.     }
  989.     else cdim = *dim;
  990.  
  991.     return(DFSDgetdimscale(cdim, *maxsize, scale));
  992. }
  993.  
  994.  
  995. /*-----------------------------------------------------------------------------
  996.  * Name:    dfsdgetrange
  997.  * Purpose: Call DFSDgetrange to get maximum and minimum data values
  998.  * Inputs:  pmax: float to return maximum in
  999.  *          pmin: float to return minimum in
  1000.  * Returns: 0 on success, -1 on failure with DFerror set
  1001.  * Users:   HDF Fortran programmers
  1002.  * Invokes: DFSDgetrange
  1003.  *---------------------------------------------------------------------------*/
  1004.  
  1005.     FRETVAL(intf)
  1006. #ifdef PROTOTYPE
  1007. ndfsdgetrange(void *pmax, void *pmin)
  1008. #else
  1009. ndfsdgetrange(pmax, pmin)
  1010.     void *pmax, *pmin;
  1011. #endif /* PROTOTYPE */
  1012. {
  1013.     return(DFSDgetrange(pmax, pmin));
  1014. }
  1015.  
  1016.  
  1017. /*-----------------------------------------------------------------------------
  1018.  * Name:    dfsdsetdims
  1019.  * Purpose: Call DFSDsetdims to set dimensions for subsequent SDGs
  1020.  * Inputs:  rank: no of dimensions of SDG
  1021.  *          dimsizes: array containing dimensions of SDG
  1022.  * Returns: 0 on success, -1 on failure with DFerror set
  1023.  * Users:   HDF Fortran programmers
  1024.  * Invokes: DFSDsetdims
  1025.  *---------------------------------------------------------------------------*/
  1026.  
  1027.     FRETVAL(intf)
  1028. #ifdef PROTOTYPE
  1029. ndfsdsetdims(intf *rank, intf dimsizes[])
  1030. #else
  1031. ndfsdsetdims(rank, dimsizes)
  1032.     intf *rank;
  1033.     intf dimsizes[];
  1034. #endif /* PROTOTYPE */
  1035. {
  1036.  
  1037.     int32 i, *cdims, *p;
  1038.     intf ret;
  1039.  
  1040.     p = (int32 *)HDgetspace((uint32)((*rank)*sizeof(int32)));
  1041.     if (p == NULL) return FAIL;
  1042.     cdims = p;
  1043.     for (i=1; i <=  *rank ; i++)    {
  1044.         *p = dimsizes[*rank - i];
  1045.         p++;
  1046.     }
  1047.    
  1048.     ret = DFSDsetdims((intn)*rank, cdims);
  1049.     cdims = HDfreespace((uint32 *)cdims);
  1050.     if (cdims != NULL) return FAIL;
  1051.     return(ret);
  1052. }
  1053.  
  1054.  
  1055. /*-----------------------------------------------------------------------------
  1056.  * Name:    dfsdsetdimscale
  1057.  * Purpose: Call DFSDsetdimscale to set scales for subsequent SDGs
  1058.  * Inputs:  dim: dimension to set scale for
  1059.  *          dimsize: size of array scale
  1060.  *          scale: array of scale values
  1061.  * Returns: 0 on success, -1 on failure with DFerror set
  1062.  * Users:   HDF Fortran programmers
  1063.  * Invokes: DFSDsetdimscale
  1064.  *---------------------------------------------------------------------------*/
  1065.  
  1066.     FRETVAL(intf)
  1067. #ifdef PROTOTYPE
  1068. ndfsdsetdimscale(intf *dim, intf *dimsize, void *scale)
  1069. #else
  1070. ndfsdsetdimscale(dim, dimsize, scale)
  1071.     intf *dim;
  1072.     intf *dimsize;
  1073.     void *scale;
  1074. #endif /* PROTOTYPE */
  1075. {
  1076.     intn rank, cdim;
  1077.     intf ret;
  1078.  
  1079.     ret = DFSDIgetwrank(&rank);
  1080.     if (rank < *dim) return FAIL;
  1081.     cdim = rank - *dim + 1;
  1082.  
  1083.     return(DFSDsetdimscale(cdim, *dimsize, scale));
  1084. }
  1085.  
  1086.  
  1087. /*-----------------------------------------------------------------------------
  1088.  * Name:    dfsdsetrange
  1089.  * Purpose: Call DFSDsetrange to set max and min values for this SDG
  1090.  * Inputs:  max, min: max and min data values
  1091.  * Returns: 0 on success, -1 on failure with DFerror set
  1092.  * Users:   HDF Fortran programmers
  1093.  * Invokes: DFSDsetrange
  1094.  * Remarks: Max and Min are set only for next SDG, reset to NULL after
  1095.  *---------------------------------------------------------------------------*/
  1096.  
  1097.     FRETVAL(intf)
  1098. #ifdef PROTOTYPE
  1099. ndfsdsetrange(void *max, void *min)
  1100. #else
  1101. ndfsdsetrange(max, min)
  1102.     void *max, *min;
  1103. #endif /* PROTOTYPE */
  1104. {
  1105.     return(DFSDsetrange(max, min));
  1106. }
  1107.  
  1108.  
  1109. /*-----------------------------------------------------------------------------
  1110.  * Name:    dfsdclear
  1111.  * Purpose: Call DFSDclear to erase values set for subsequent SDGs
  1112.  * Inputs:  none
  1113.  * Returns: 0 on success, -1 on failure with DFerror set
  1114.  * Users:   HDF Fortran programmers
  1115.  * Invokes: DFSDclear
  1116.  *---------------------------------------------------------------------------*/
  1117.  
  1118.     FRETVAL(intf)
  1119. #ifdef PROTOTYPE
  1120. ndfsdclear(void)
  1121. #else
  1122. ndfsdclear()
  1123. #endif /* PROTOTYPE */
  1124. {
  1125.     return(DFSDclear());
  1126. }
  1127.  
  1128.  
  1129. /*-----------------------------------------------------------------------------
  1130.  * Name:    dfsdsetlengths
  1131.  * Purpose: Call DFSDsetlengths to set max lengths of strings
  1132.  * Inputs:  maxlen_label, maxlen_unit, maxlen_format, maxlen_coordsys: max lens
  1133.  * Returns: 0 on success, -1 on failure with DFerror set
  1134.  * Users:   HDF Fortran programmers
  1135.  * Invokes: DFSDsetlengths
  1136.  *---------------------------------------------------------------------------*/
  1137.  
  1138.     FRETVAL(intf)
  1139. #ifdef PROTOTYPE
  1140. ndfsdsetlengths(intf *maxlen_label, intf *maxlen_unit, intf *maxlen_format,
  1141.         intf *maxlen_coordsys)
  1142. #else
  1143. ndfsdsetlengths(maxlen_label, maxlen_unit, maxlen_format, maxlen_coordsys)
  1144.     intf *maxlen_label, *maxlen_unit, *maxlen_format, *maxlen_coordsys;
  1145. #endif /* PROTOTYPE */
  1146. {
  1147.     return(DFSDsetlengths(*maxlen_label, *maxlen_unit, *maxlen_format,
  1148.                                                         *maxlen_coordsys));
  1149. }
  1150.  
  1151.  
  1152. /*-----------------------------------------------------------------------------
  1153.  * Name:    dfsdgetdimlen
  1154.  * Purpose: Call DFSDgetdimlen to get actual lengths of strings
  1155.  * Inputs:  dim: dimension to get lengths for
  1156.  *         llabel, lunit, lformat: integers to return lengths of each string in
  1157.  * Returns: 0 on success, -1 on failure with DFerror set
  1158.  * Users:   HDF Fortran programmers
  1159.  * Invokes: DFSDgetdimlen
  1160.  *---------------------------------------------------------------------------*/
  1161.  
  1162.     FRETVAL(intf)
  1163. #ifdef PROTOTYPE
  1164. ndfsdgetdimlen(intf *dim, intf *llabel, intf *lunit, intf *lformat)
  1165. #else
  1166. ndfsdgetdimlen(dim, llabel, lunit, lformat)
  1167.     intf *dim, *llabel, *lunit, *lformat;
  1168. #endif /* PROTOTYPE */
  1169. {
  1170.     intn isndg;
  1171.     intn rank, cdim;
  1172.     intf ret;
  1173.  
  1174.     ret = DFSDIisndg(&isndg);
  1175.     if (isndg)     {
  1176.         ret = DFSDIgetrrank(&rank);
  1177.         if (rank < *dim) return FAIL;
  1178.         cdim = rank - *dim + 1;
  1179.     }
  1180.     else cdim = *dim;
  1181.  
  1182.     return(DFSDgetdimlen(cdim, llabel, lunit, lformat));
  1183. }
  1184.  
  1185.  
  1186. /*-----------------------------------------------------------------------------
  1187.  * Name:    dfsdgetdatalen
  1188.  * Purpose: Call DFSDgetdatalen to get actual lengths of strings
  1189.  * Inputs:  llabel, lunit, lformat, lcoordsys: integers to return lengths in
  1190.  * Returns: 0 on success, -1 on failure with DFerror set
  1191.  * Users:   HDF Fortran programmers
  1192.  * Invokes: DFSDgetdatalen
  1193.  *---------------------------------------------------------------------------*/
  1194.  
  1195.     FRETVAL(intf)
  1196. #ifdef PROTOTYPE
  1197. ndfsdgetdatalen(intf *llabel, intf *lunit, intf *lformat, intf *lcoordsys)
  1198. #else
  1199. ndfsdgetdatalen(llabel, lunit, lformat, lcoordsys)
  1200.     intf *llabel, *lunit, *lformat, *lcoordsys;
  1201. #endif /* PROTOTYPE */
  1202. {
  1203.     return(DFSDgetdatalen(llabel, lunit, lformat, lcoordsys));
  1204. }
  1205.  
  1206.  
  1207. /*-----------------------------------------------------------------------------
  1208.  * Name:    dfsdrestart
  1209.  * Purpose: Call DFSDrestart to get SDGs again from the beginning
  1210.  * Inputs:  none
  1211.  * Returns: 0 on success, -1 on failure with DFerror set
  1212.  * Users:   HDF Fortran programmers
  1213.  * Invokes: DFSDrestart
  1214.  *---------------------------------------------------------------------------*/
  1215.  
  1216.     FRETVAL(intf)
  1217. #ifdef PROTOTYPE
  1218. ndfsdrestart(void)
  1219. #else
  1220. ndfsdrestart()
  1221. #endif /* PROTOTYPE */
  1222. {
  1223.     return(DFSDrestart());
  1224. }
  1225.  
  1226.  
  1227. /*-----------------------------------------------------------------------------
  1228.  * Name:    dfsdputslice
  1229.  * Purpose: Call DFSDIputslice to write slice to file
  1230.  * Inputs:  winst: array of size = rank of data, containing start of slice
  1231.  *          windims: array of size rank, containing end of slice
  1232.  *          data: array containing slice
  1233.  *          dims: dimensions of array data
  1234.  * Returns: 0 on success, -1 on failure with DFerror set
  1235.  * Users:   HDF Fortran programmers
  1236.  * Invokes: DFSDIputslice
  1237.  *---------------------------------------------------------------------------*/
  1238.  
  1239.     FRETVAL(intf)
  1240. #ifdef PROTOTYPE
  1241. ndfsdputslice(intf windims[], void *data, intf dims[])
  1242. #else
  1243. ndfsdputslice(windims, data, dims)
  1244.     intf windims[];
  1245.     void *data;
  1246.     intf dims[];
  1247. #endif /* PROTOTYPE */
  1248. {
  1249.     intn rank, i;
  1250.     intf ret;
  1251.     int32 *cdims, *cwindims, *p, *wp;
  1252.  
  1253.     ret = DFSDIgetwrank(&rank);
  1254.     wp = (int32 *)HDgetspace((uint32)((rank)*sizeof(int32)));
  1255.     if (wp == NULL) return FAIL;
  1256.     cwindims = wp;
  1257.     p = (int32 *)HDgetspace((uint32)((rank)*sizeof(int32)));
  1258.     if (p == NULL) return FAIL;
  1259.     cdims = p;
  1260.     for (i=1; i <=  rank ; i++)    {  /* reverse dims & windims */
  1261.         *p = dims[rank - i];
  1262.         p++;
  1263.         *wp = windims[rank - i];
  1264.         wp++;
  1265.     }
  1266.    
  1267.     ret = DFSDIputslice(cwindims, data, cdims, 1);
  1268.     cdims = HDfreespace((uint32 *)cdims);
  1269.     if (cdims != NULL) return FAIL;
  1270.     cwindims = HDfreespace((uint32 *)cwindims);
  1271.     if (cwindims != NULL) return FAIL;
  1272.     return(ret);
  1273. }
  1274.  
  1275. /*-----------------------------------------------------------------------------
  1276.  * Name:    dfsdendslice
  1277.  * Purpose: Call DFSDendslice to finish slice writes and write out SDG
  1278.  * Inputs:  none
  1279.  * Returns: 0 on success, -1 on failure with DFerror set
  1280.  * Users:   HDF Fortran programmers
  1281.  * Invokes: DFSDIendslice
  1282.  *---------------------------------------------------------------------------*/
  1283.  
  1284.     FRETVAL(intf)
  1285. #ifdef PROTOTYPE
  1286. ndfsdendslice(void)
  1287. #else
  1288. ndfsdendslice()
  1289. #endif /* PROTOTYPE */
  1290. {
  1291.     return(DFSDIendslice(1));
  1292. }
  1293.  
  1294.  
  1295. /*-----------------------------------------------------------------------------
  1296.  * Name:    dfsdpre32
  1297.  * Purpose: test if the SDS was  written using HDF library previous 
  1298.  *          to HDF3.2
  1299.  * Output:  ispre32 is 0 if written by 3.2, 1 if by 3.1
  1300.  * Returns: 0 on success, FAIL on failure with error set
  1301.  * Users:   HDF Fortran programmers
  1302.  * Method:  Invokes DFSDpre32
  1303.  * Remarks: 0 specifies default value
  1304.  *---------------------------------------------------------------------------*/
  1305.  
  1306.         FRETVAL(intf)
  1307. #ifdef PROTOTYPE
  1308. ndfsdpre32(void)
  1309. #else
  1310. ndfsdpre32()
  1311. #endif /* PROTOTYPE */
  1312. {
  1313.     return(DFSDpre32());
  1314. }
  1315.  
  1316. /*-----------------------------------------------------------------------------
  1317.  * Name:    dfsdsetnt
  1318.  * Purpose: Call DFSDsetNT to set number type for subsequent calls to
  1319.  *          DFSDputdata, DFSDadddata, DFSDsetdimscales.
  1320.  * Inputs:  numbertype
  1321.  * Returns: 0 on success, FAIL on failure with error set
  1322.  * Users:   HDF Fortran programmers
  1323.  * Method:  Invokes DFSDsetNT
  1324.  * Remarks: 0 specifies default value
  1325.  *---------------------------------------------------------------------------*/
  1326.  
  1327.         FRETVAL(intf)
  1328. #ifdef PROTOTYPE
  1329. ndfsdsetnt(intf *numbertype)
  1330. #else
  1331. ndfsdsetnt(numbertype)
  1332.     intf *numbertype;
  1333. #endif /* PROTOTYPE */
  1334. {
  1335.     return(DFSDsetNT(*numbertype));
  1336. }
  1337.  
  1338. /*-----------------------------------------------------------------------------
  1339.  * Name:    dfsdgetnt
  1340.  * Purpose: Call DFSDgetNT to get number type for subsequent calls 
  1341.  * Inputs:  pnumbertype
  1342.  * Returns: 0 on success, FAIL on failure with error set
  1343.  * Users:   HDF Fortran programmers
  1344.  * Method:  Invokes DFSDgetNT
  1345.  * Remarks: 0 specifies default value
  1346.  *---------------------------------------------------------------------------*/
  1347.  
  1348.     FRETVAL(intf)
  1349. #ifdef PROTOTYPE
  1350. ndfsdgetnt(intf *pnumbertype)
  1351. #else
  1352. ndfsdgetnt(pnumbertype)
  1353.     intf *pnumbertype;
  1354. #endif /* PROTOTYPE */
  1355. {
  1356.     return(DFSDgetNT((int32 *)pnumbertype));
  1357. }
  1358.  
  1359. /*-----------------------------------------------------------------------------
  1360.  * Name:    dfsdlastref
  1361.  * Purpose: Return last ref written or read
  1362.  * Inputs:  none
  1363.  * Globals: Lastref
  1364.  * Returns: ref on success, -1 on error with DFerror set
  1365.  * Users:   HDF users, utilities, other routines
  1366.  * Invokes: DFANlastref
  1367.  * Remarks: none
  1368.  *---------------------------------------------------------------------------*/
  1369.  
  1370.     FRETVAL(intf)
  1371. #ifdef PROTOTYPE
  1372. ndfsdlastref(void)
  1373. #else
  1374. ndfsdlastref()
  1375. #endif /* PROTOTYPE */
  1376. {
  1377.     return(DFSDlastref());
  1378. }
  1379.  
  1380. /*-----------------------------------------------------------------------------
  1381.  * Name:    dsisdis
  1382.  * Purpose: For the given dimension, set label, unit, format
  1383.  *          This routine needs to be called once for each dimension whose 
  1384.  *          values the user wants to set.
  1385.  * Inputs:  dim: the dimension that this info applies to
  1386.  *          label: label to be used to describe this dimension
  1387.  *          unit: units for dimension
  1388.  *          format: format to be used in displaying
  1389.  *          llabel, lunit, lformat: lengths of corresponding strings
  1390.  * Globals: 
  1391.  * Returns: 0 on success, FAIL on failure with error set
  1392.  * Users:   HDF users, utilities, other routines
  1393.  * Invokes: DFSDIsetdimstr
  1394.  * Method:  
  1395.  *---------------------------------------------------------------------------*/
  1396.  
  1397.     FRETVAL(intf)
  1398. #ifdef PROTOTYPE
  1399. ndsisdis(intf *dim, _fcd flabel, _fcd funit, _fcd fformat,
  1400.      intf *llabel, intf *lunit, intf *lformat)
  1401. #else
  1402. ndsisdis(dim, flabel, funit, fformat, llabel, lunit, lformat)
  1403.     intf *dim;
  1404.     _fcd flabel, funit, fformat;
  1405.     intf *llabel, *lunit, *lformat;
  1406. #endif /* PROTOTYPE */
  1407. {
  1408.     char *label  =  HDf2cstring(flabel, *llabel);
  1409.     char *unit   =  HDf2cstring(funit, *lunit);  
  1410.     char *format =  HDf2cstring(fformat, *lformat);
  1411.     intf status;
  1412.     intn isndg;
  1413.     intn rank, cdim;
  1414.  
  1415.     status = DFSDIgetwrank(&rank);
  1416.  
  1417.     if (rank < *dim) return FAIL;
  1418.     cdim = rank - *dim + 1;
  1419.     
  1420.     status = DFSDIsetdimstrs(cdim, label, unit, format);
  1421.  
  1422.     HDfreespace(label);
  1423.     HDfreespace(unit);
  1424.     HDfreespace(format);
  1425.  
  1426.     return status;
  1427.  
  1428. }
  1429.  
  1430. /*-----------------------------------------------------------------------------
  1431.  * Name:    dsigdis
  1432.  * Purpose: Call DFSDgetdimstrs to get attributes of a dimension
  1433.  * Inputs:  label, unit, format: strings to return attributes in
  1434.  * Returns: 0 on success, -1 on failure with DFerror set
  1435.  * Users:   HDF Fortran programmers
  1436.  * Invokes: DFSDgetdimstrs
  1437.  *---------------------------------------------------------------------------*/
  1438.  
  1439.     FRETVAL(intf)
  1440. #ifdef PROTOTYPE
  1441. ndsigdis(intf *dim, _fcd label, _fcd unit, _fcd format, intf *llabel,
  1442.          intf *lunit, intf *lformat)
  1443. #else
  1444. ndsigdis(dim, label, unit, format, llabel, lunit, lformat)
  1445.      intf *dim;
  1446.      _fcd label, unit, format;
  1447.      intf *llabel, *lunit, *lformat;
  1448. #endif /* PROTOTYPE */
  1449. {
  1450.     char *ilabel, *iunit, *iformat;
  1451.     intn rank, cdim;
  1452.     intf ret;
  1453.     intn isndg, status;
  1454.  
  1455.     ret = DFSDIisndg(&isndg);
  1456.     if (isndg)     {
  1457.         ret = DFSDIgetrrank(&rank);
  1458.         if (rank < *dim) return FAIL;
  1459.         cdim = rank - *dim + 1;
  1460.     }
  1461.     else cdim = *dim;
  1462.  
  1463.     iunit = ilabel = iformat = NULL;
  1464.  
  1465.     if(*llabel)  ilabel  = (char *) HDgetspace((uint32)*llabel + 1);
  1466.     if(*lunit)   iunit   = (char *) HDgetspace((uint32)*lunit + 1);
  1467.     if(*lformat) iformat = (char *) HDgetspace((uint32)*lformat + 1);
  1468.  
  1469.     status = DFSDgetdimstrs(cdim, ilabel, iunit, iformat);
  1470.  
  1471.     HDpackFstring(ilabel,  _fcdtocp(label),  *llabel);
  1472.     HDpackFstring(iunit,   _fcdtocp(unit),   *lunit);
  1473.     HDpackFstring(iformat, _fcdtocp(format), *lformat);
  1474.  
  1475.     if(ilabel)  HDfreespace(ilabel);
  1476.     if(iunit)   HDfreespace(iunit);
  1477.     if(iformat) HDfreespace(iformat);
  1478.  
  1479.     return status;
  1480. }
  1481.  
  1482. /*-----------------------------------------------------------------------------
  1483.  * Name:    DFSDIsetdatastrs()
  1484.  * Purpose: Set label, unit and format for displaying subsequent SDGs
  1485.  * Inputs:  label: label to be used to describe data
  1486.  *          unit: unit corresponding to data values
  1487.  *          format: format to be used in displaying data values
  1488.  *          coordsys: type of coordinate system
  1489.  * Globals: Writesdg, Ref
  1490.  * Returns: 0 on success, FAIL on failure with error set
  1491.  * Users:   HDF Fortran stubs
  1492.  * Invokes: DFSDIsetdatastrs
  1493.  * Method:  Stores values in global structure Writesdg
  1494.  * Remarks: 
  1495.  *---------------------------------------------------------------------------*/
  1496.     FRETVAL(intf)
  1497. #ifdef PROTOTYPE
  1498. ndsisdas(_fcd flabel, _fcd funit, _fcd fformat, _fcd fcoordsys, intf *isfortran,
  1499.      intf *llabel, intf *lunit, intf *lformat, intf *lcoordsys)
  1500. #else
  1501. ndsisdas(flabel, funit, fformat, fcoordsys, isfortran, llabel, lunit,
  1502.      lformat, lcoordsys)
  1503.     _fcd flabel, funit, fformat, fcoordsys;
  1504.     intf *isfortran;
  1505.     intf *llabel, *lunit, *lformat, *lcoordsys;
  1506. #endif /* PROTOTYPE */
  1507. {
  1508.     char *label    =  HDf2cstring(flabel, *llabel);
  1509.     char *unit     =  HDf2cstring(funit, *lunit);  
  1510.     char *format   =  HDf2cstring(fformat, *lformat);
  1511.     char *coordsys =  HDf2cstring(fcoordsys, *lcoordsys);
  1512.     intf status;
  1513.  
  1514.     status = DFSDIsetdatastrs(label, unit, format, coordsys);
  1515.  
  1516.     HDfreespace(label);
  1517.     HDfreespace(unit);
  1518.     HDfreespace(format);
  1519.     HDfreespace(coordsys);
  1520.  
  1521.     return status;
  1522. } /* ndsisdas */
  1523.  
  1524. /*-----------------------------------------------------------------------------
  1525.  * Name:    dsigdas
  1526.  * Purpose: Call DFSDgetdatastrs to get the data attributes
  1527.  * Inputs:  label, unit, format, coordsys: strings to return attributes in
  1528.  * Returns: 0 on success, -1 on failure with    DFerror set
  1529.  * Users:   HDF Fortran programmers
  1530.  * Invokes: DFSDgetdatastrs
  1531.  *---------------------------------------------------------------------------*/
  1532.  
  1533.     FRETVAL(intf)
  1534. #ifdef PROTOTYPE
  1535. ndsigdas(_fcd label, _fcd unit, _fcd format, _fcd coordsys, intf *llabel,
  1536.         intf *lunit, intf *lformat, intf *lcoord)
  1537. #else
  1538. ndsigdas(label, unit, format, coordsys, llabel, lunit, lformat, lcoord)
  1539.      _fcd label, unit, format, coordsys;
  1540.      intf *llabel, *lunit, *lformat, *lcoord;
  1541. #endif /* PROTOTYPE */
  1542. {
  1543.     char *ilabel, *iunit, *iformat, *icoord;
  1544.     intf status;
  1545.  
  1546.     iunit = ilabel = iformat = icoord = NULL;
  1547.  
  1548.     if(*llabel)  ilabel  = (char *) HDgetspace((uint32)*llabel + 1);
  1549.     if(*lunit)   iunit   = (char *) HDgetspace((uint32)*lunit + 1);
  1550.     if(*lformat) iformat = (char *) HDgetspace((uint32)*lformat + 1);
  1551.     if(*lcoord)  icoord  = (char *) HDgetspace((uint32)*lcoord + 1);
  1552.  
  1553.     status = DFSDgetdatastrs(ilabel, iunit, iformat, icoord);
  1554.     
  1555.     HDpackFstring(ilabel,  _fcdtocp(label),    *llabel);
  1556.     HDpackFstring(iunit,   _fcdtocp(unit),     *lunit);
  1557.     HDpackFstring(iformat, _fcdtocp(format),   *lformat);
  1558.     HDpackFstring(icoord,  _fcdtocp(coordsys), *lcoord);
  1559.  
  1560.     if(ilabel)  HDfreespace(ilabel);
  1561.     if(iunit)   HDfreespace(iunit);
  1562.     if(iformat) HDfreespace(iformat);
  1563.     if(icoord)  HDfreespace(icoord);
  1564.  
  1565.     return status;
  1566.  
  1567. }
  1568.  
  1569. /*-----------------------------------------------------------------------------
  1570.  * Name:    dsscal
  1571.  * Purpose: Call DFSDsetcal to set calibration data
  1572.  * Inputs:  cal, cal_err   : calibration and error
  1573.  *          ioff, ioff_err : offset and error
  1574.  *          cal_type       : after calibration NT
  1575.  * Returns: 0 on success, -1 on failure
  1576.  * Users:   HDF Fortran programmers
  1577.  * Invokes: DFSDgetdatastrs
  1578.  *---------------------------------------------------------------------------*/
  1579.     FRETVAL(intf)
  1580. #ifdef PROTOTYPE
  1581. ndsscal(float64 *cal, float64 *cal_err, float64 *ioff, float64 *ioff_err,
  1582.          intf * cal_type)
  1583. #else
  1584. ndsscal(cal, cal_err, ioff, ioff_err, cal_type)
  1585.      float64 *cal, *cal_err, *ioff, *ioff_err;
  1586.      int32   *cal_type;
  1587. #endif /* PROTOTYPE */
  1588. {
  1589.     return DFSDsetcal(*cal, *cal_err, *ioff, *ioff_err, *cal_type);
  1590. } /* ndsscal */
  1591.  
  1592. /*-----------------------------------------------------------------------------
  1593.  * Name:    dsgcal
  1594.  * Purpose: Call DFSDgetcal to get calibration data
  1595.  * Inputs:  cal, cal_err   : calibration and error
  1596.  *          ioff, ioff_err : offset and error
  1597.  *          cal_type       : after calibration NT
  1598.  * Returns: 0 on success, -1 on failure
  1599.  * Users:   HDF Fortran programmers
  1600.  * Invokes: DFSDgetdatastrs
  1601.  *---------------------------------------------------------------------------*/
  1602.  
  1603.     FRETVAL(intf)
  1604. #ifdef PROTOTYPE
  1605. ndsgcal(float64 *cal, float64 *cal_err, float64 *ioff, float64 *ioff_err,
  1606.          intf * cal_type)
  1607. #else
  1608. ndsgcal(cal, cal_err, ioff, ioff_err, cal_type)
  1609.      float64 *cal, *cal_err, *ioff, *ioff_err;
  1610.      intf   *cal_type;
  1611. #endif /* PROTOTYPE */
  1612. {
  1613.     return DFSDgetcal(cal, cal_err, ioff, ioff_err, (int32 *)cal_type);
  1614. } /* ndsgcal */
  1615.